package main

import (
	"fmt"
	"time"
)

// getISOWeek 获取给定时间的ISO 8601周数
func getISOWeek(t time.Time) (int, int) {
	return t.ISOWeek()
}

const layout = "2006-01-02"

func pareToTime(dateStr string) (time.Time, error) {
	// 解析时间字符串
	t, err := time.Parse(layout, dateStr)
	if err != nil {
		fmt.Println("解析时间错误：", err)
		return time.Now(), err
	}
	fmt.Println("解析后的时间：", t)
	return t, nil
}
func getIdByWeek(week, year int) int {
	return (year*100 + week) * 10000
}
func getIdByDateStr(dateStr string) int {
	t, _ := pareToTime(dateStr)
	year, week := getISOWeek(t)
	id := getIdByWeek(week, year)
	fmt.Println(id)
	return id
}

func main() {
	now := time.Now()
	date := now.AddDate(0, 0, -4)
	fmt.Println(date)
	year, week := getISOWeek(date)

	fmt.Printf("当前时间是%d年的第%d周\n", year, week)

	str := "2024-10-11"
	getIdByDateStr(str)
}
